﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Permissions;
using System.Runtime.InteropServices;

namespace GenericTools
{
    public static class Win32Api
    {
        public const int CM_LOCATE_DEVNODE_NORMAL = 0x00000000;
        public const int CM_REENUMERATE_NORMAL = 0x00000000;
        public const int CM_REENUMERATE_SYNCHRONOUS = 0x00000001;
        public const int CM_REENUMERATE_RETRY_INSTALLATION = 0x00000002;
        public const int CM_REENUMERATE_ASYNCHRONOUS = 0x00000004;
        public const int CM_REENUMERATE_BITS = 0x00000007;

        public const int CR_SUCCESS = 0x00000000;
        public const int CR_ACCESS_DENIED = 0x00000033;

        [DllImport("CfgMgr32.dll", SetLastError = true)]
        public static extern int CM_Locate_DevNodeA(ref int pdnDevInst, string pDeviceID, int ulFlags);

        [PrincipalPermissionAttribute(SecurityAction.Demand, Role = @"BUILTIN\Administrators")]
        [DllImport("CfgMgr32.dll", SetLastError = true)]
        public static extern int CM_Reenumerate_DevNode(int dnDevInst, int ulFlags);
    }
}
